#include "wds_object_player.h"




CPlayer::CPlayer(float pLife,float pX,float pY,float pWidth,float pHeight,int pLimitX,int pLimitY,float pMoveSpeed) : WDSObject()
{
	mLife = pLife;
	init(pX,pY,pWidth,pHeight,pLimitX,pLimitY,pMoveSpeed);
	mIsGoingDown = false;
	mIsGoingUp = false;
	mIsGoingLeft = false;
	mIsGoingRight = false;
	mIsFiring = false;
	
	
	mSinceLastWeaponFireTime = 100;
	
		
}


void CPlayer::setWeapon (CWeapon *pCWeapon)
{
	mCWeapon = pCWeapon;
}

void CPlayer::setCursor(WDSObject *pPointObject)
{
	mPointObject = pPointObject;
}

void CPlayer::getKeyInput()
{
	/*
	if(mIsGoingDown == false)
	{
		if(mHge->Input_KeyDown(HGEK_S) || mHge->Input_KeyDown(HGEK_DOWN))
			mIsGoingDown = true;
	}
	else
	{
		if(mHge->Input_KeyUp(HGEK_S) || mHge->Input_KeyUp(HGEK_DOWN))
			mIsGoingDown = false;
	}

	if(mIsGoingUp == false)
	{
		if(mHge->Input_KeyDown(HGEK_W) || mHge->Input_KeyDown(HGEK_UP))
			mIsGoingUp = true;
	}
	else
	{
		if(mHge->Input_KeyUp(HGEK_W) || mHge->Input_KeyUp(HGEK_UP))
			mIsGoingUp = false;
	}

	if(mIsGoingLeft == false)
	{
		if(mHge->Input_KeyDown(HGEK_A) || mHge->Input_KeyDown(HGEK_LEFT))
			mIsGoingLeft = true;
	}
	else
	{
		if(mHge->Input_KeyUp(HGEK_A) || mHge->Input_KeyUp(HGEK_LEFT))
			mIsGoingLeft = false;
	}
	
	if(mIsGoingRight == false)
	{
		if(mHge->Input_KeyDown(HGEK_D ) || mHge->Input_KeyDown(HGEK_RIGHT))
			mIsGoingRight  = true;
	}
	else
	{
		if(mHge->Input_KeyUp(HGEK_D) || mHge->Input_KeyUp(HGEK_RIGHT))
			mIsGoingRight = false;
	}

	if(mIsFiring == false)
	{
		if(mHge->Input_KeyDown(HGEK_LBUTTON) || mHge->Input_KeyDown(HGEK_RBUTTON) || mHge->Input_KeyDown(HGEK_SPACE))
			mIsFiring  = true;
	}
	else
	{
		if(mHge->Input_KeyUp(HGEK_LBUTTON) || mHge->Input_KeyUp(HGEK_RBUTTON) ||  mHge->Input_KeyUp(HGEK_SPACE) )
			mIsFiring = false;
	}
	*/

}

void CPlayer::Tick(float dt)
{
	getKeyInput();
	
	Move((getGoingRight()-getGoingLeft())* dt,(getGoingDown()-getGoingUp())*dt );

	// todo : rewrite Rotation 
	//mRotation = atan2( getViewportY() -  mPointObject->getY() , getViewportX() -  mPointObject->getX() );	
	//mRotation += M_PI_2; 		

	//todo: add weapon class
	//if(mIsFiring && mSinceLastWeaponFireTime > mCWeapon->getBulletFrequency())
	{
		mSinceLastWeaponFireTime = 0;
	//	mCWeapon->fire(getX(),getY(),getRotation());			
	}		
	if(mSinceLastWeaponFireTime < 100)
		mSinceLastWeaponFireTime += dt;		
}



float  CPlayer::getGoingDown() const
{
	if(mIsGoingDown)	
		return mMoveSpeed;

	return 0;
}

float CPlayer::getGoingUp() const
{
	if(mIsGoingUp)	
		return mMoveSpeed;

	return 0;
}

float CPlayer::getGoingLeft() const
{
	if(mIsGoingLeft)	
		return mMoveSpeed;

	return 0;
}

float CPlayer::getGoingRight() const
{
	if(mIsGoingRight)	
		return mMoveSpeed;

	return 0;
}
